package com.nami.logic.serializer.fury;


import com.nami.basic.bo.servicetrans.LoginReplyBo;
import com.nami.basic.packet.Packet;
import lombok.extern.slf4j.Slf4j;
import org.apache.fury.Fury;
import org.apache.fury.ThreadLocalFury;
import org.apache.fury.ThreadSafeFury;
import org.apache.fury.config.Language;

/**
 * 描述:
 *
 * @author: lbc
 * @date: 2024-08-11 15:52
 * @description: keep coding
 * @since 1.0.0
 */
@Slf4j
public class FuryFactory {

    private static final ThreadSafeFury fury;

    static {
        fury = newFury();
    }

    public static ThreadSafeFury newFury() {
//        ThreadSafeFury fury = Fury.builder().withLanguage(Language.JAVA)
//            .requireClassRegistration(true)
//            .buildThreadSafeFury();
//        // Registering types can reduce class name serialization overhead, but not mandatory.
//        // If class registration enabled, all custom types must be registered.
//        fury.register(LoginReplyBo.class);
//        fury.register(Packet.class);
        ThreadSafeFury fury1 = new ThreadLocalFury(classLoader -> {
            Fury f = Fury.builder().withLanguage(Language.JAVA)
                .withClassLoader(classLoader).build();

        f.register(LoginReplyBo.class);
        f.register(Packet.class);
            return f;
        });
        log.info("[fury-init] 初始化fury.");
        return fury1;
    }

    public static ThreadSafeFury getFury() {
        return fury;
    }


}
